package com.jky.stmall.front.config;


import com.jky.stmall.front.interceptor.UserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Value("${upload.path}")
    private String path;

    @Autowired
    private UserInterceptor userInterceptor;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**",
                        "/upload/**")
                .addResourceLocations("classpath:/static/",
                        "file:"+path);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器的方法
        registry.addInterceptor(userInterceptor).addPathPatterns("/user/**")
                .excludePathPatterns("/user/login","/user/reg");
    }
}
